﻿using CarbonExchange.LinqUtilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;

namespace CarbonExchange.Tests
{
    [TestClass]
    public class FormatStringHelperTests : BaseTest
    {
        [TestMethod]
        public void FormatStringHelper_ToFormatString_WithOneArg()
        {
            var tmp = _TestCountries.AsQueryable().ToFormatedString("<li>{0}</li>", x => x.Locale);
            Assert.AreEqual("<li>United Kingdom</li><li>Switzerland</li>", tmp);

        }

        [TestMethod]
        public void FormatStringHelper_ToFormatString_WithTwoArgs()
        {
            var tmp = _TestCountries.AsQueryable().ToFormatedString("_Name: '{1}' Created On: '{0:dd/MM/yyyy}'-", x => x.Created.ToLocalTime(), x => x.Locale);
            Assert.AreEqual("_Name: 'United Kingdom' Created On: '24/10/1975'-_Name: 'Switzerland' Created On: '24/10/1975'-", tmp);
        }

        [TestMethod]
        public void FormatStringHelper_ToFormatStringWithSpacer_WithOneArg()
        {
            var tmp = _TestCountries.AsQueryable().ToFormatedStringWithSpacer(", ", "{0}", x => x.Locale);
            Assert.AreEqual("United Kingdom, Switzerland", tmp);

        }

        [TestMethod]
        public void FormatStringHelper_ToFormatStringWithSpacer_WithTwoArgs()
        {
            _TestCountries[1].Deleted = true;
            var tmp = _TestCountries.AsQueryable().ToFormatedStringWithSpacer(", ", "{0} is {1}deleted", x => x.Locale, x => x.Deleted ? "" : "not ");
            Assert.AreEqual("United Kingdom is not deleted, Switzerland is deleted", tmp);

        }

        [TestMethod]
        public void FormatStringHelper_ToFormatStringWithSpacer_WithNoFormatString()
        {
            var tmp = _TestCountries.AsQueryable().ToFormatedStringWithSpacer("|", x => x.Locale, x => x.Deleted, x => x.Created.ToLocalTime().ToShortDateString());
            Assert.AreEqual("United Kingdom, False, 24/10/1975|Switzerland, False, 24/10/1975", tmp);

        }

    }
}
